﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CMS.Dialogs.Notifications
{
    public class NoticePublisher : INoticePublisher
    {
        /// <summary>
        /// 消息队列
        /// </summary>
        private readonly ConcurrentQueue<string> _Queue = new ConcurrentQueue<string>();


        public bool Available()
        {
            return !_Queue.IsEmpty;
        }

        public void Clear()
        {
            while (_Queue.TryDequeue(out string result)) ;
        }

        public string ReadLine()
        {
            if (_Queue.TryDequeue(out string result))
            {
                return result;
            }
            else
            {
                return null;
            }
        }

        public void WriteLine(string catalog, string line)
        {
            _Queue.Enqueue($"[{catalog,-5}]:{line}\r\n");
        }
    }
}
